using System;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Collections.Generic;
using System.Reflection;

namespace Xdt.Archives.Data
{
  /// <summary>
  /// Files Data Object Class
  /// </summary>
  public partial class DOFiles
  {
    #region Class Constant declarations
    		/// <summary>
		/// The Table Column for the Files FileNo
		/// </summary>
		public const string RowFileNo = "FileNo";

		/// <summary>
		/// The Table Column for the Files BoxNo
		/// </summary>
		public const string RowBoxNo = "BoxNo";

		/// <summary>
		/// The Table Column for the Files DivisionName
		/// </summary>
		public const string RowDivisionName = "DivisionName";

		/// <summary>
		/// The Table Column for the Files DepartmentName
		/// </summary>
		public const string RowDepartmentName = "DepartmentName";

		/// <summary>
		/// The Table Column for the Files CategoryName
		/// </summary>
		public const string RowCategoryName = "CategoryName";

		/// <summary>
		/// The Table Column for the Files ProductName
		/// </summary>
		public const string RowProductName = "ProductName";

		/// <summary>
		/// The Table Column for the Files ArchiveId
		/// </summary>
		public const string RowArchiveId = "Archive_ID";

		/// <summary>
		/// The Table Column for the Files FileStatus
		/// </summary>
		public const string RowFileStatus = "FileStatus";

		/// <summary>
		/// The Table Column for the Files Notes
		/// </summary>
		public const string RowNotes = "Notes";

		/// <summary>
		/// The Table Column for the Files Description
		/// </summary>
		public const string RowDescription = "Description";

		/// <summary>
		/// The Table Column for the Files FromNo
		/// </summary>
		public const string RowFromNo = "FromNo";

		/// <summary>
		/// The Table Column for the Files ToNo
		/// </summary>
		public const string RowToNo = "ToNo";

		/// <summary>
		/// The Table Column for the Files FromDate
		/// </summary>
		public const string RowFromDate = "FromDate";

		/// <summary>
		/// The Table Column for the Files ToDate
		/// </summary>
		public const string RowToDate = "ToDate";

		/// <summary>
		/// The Table Column for the Files FromAlpha
		/// </summary>
		public const string RowFromAlpha = "FromAlpha";

		/// <summary>
		/// The Table Column for the Files ToAlpha
		/// </summary>
		public const string RowToAlpha = "ToAlpha";

		/// <summary>
		/// The Table Column for the Files CreatedDate
		/// </summary>
		public const string RowCreatedDate = "CreatedDate";

		/// <summary>
		/// The Table Column for the Files CreatedByUserId
		/// </summary>
		public const string RowCreatedByUserId = "CreatedByUser_ID";

		/// <summary>
		/// The Table Column for the Files RequestId
		/// </summary>
		public const string RowRequestId = "Request_ID";

		/// <summary>
		/// The Table Column for the Files RequestDate
		/// </summary>
		public const string RowRequestDate = "RequestDate";

		/// <summary>
		/// The Table Column for the Files RequestedByUserId
		/// </summary>
		public const string RowRequestedByUserId = "RequestedByUser_ID";

		/// <summary>
		/// The Table Column for the Files RequestedDate
		/// </summary>
		public const string RowRequestedDate = "RequestedDate";


#region Stored Procedures
private const string m_StoredProcedureConstCreate = "spFiles_Create";
private const string m_StoredProcedureConstDelete = "spFiles_Delete";
private const string m_StoredProcedureConstRetrieve = "spFiles_Retrieve";
private const string m_StoredProcedureConstRetrieveall = "spFiles_Retrieveall";
private const string m_StoredProcedureConstUpdate = "spFiles_Update";
#endregion
    
    
    #endregion

    #region Class Variable declarations
    	#region DO Variables
		private string m_FileNo;
		private string m_BoxNo;
		private string m_DivisionName;
		private string m_DepartmentName;
		private string m_CategoryName;
		private string m_ProductName;
		private int m_ArchiveId;
		private string m_FileStatus;
		private string m_Notes;
		private string m_Description;
		private int m_FromNo;
		private int m_ToNo;
		private DateTime m_FromDate;
		private DateTime m_ToDate;
		private string m_FromAlpha;
		private string m_ToAlpha;
		private DateTime m_CreatedDate;
		private long m_CreatedByUserId;
		private int m_RequestId;
		private DateTime m_RequestDate;
		private long m_RequestedByUserId;
		private DateTime m_RequestedDate;
	#endregion
    
	#region Default Variables
	private SQLDataObject sqlData;
	private List<DOFiles> m_Filess = new List<DOFiles>();
	#endregion
	
    #endregion

    #region Class Constructors & Destructors
    /// <summary>
    /// Class Constructor
    /// </summary>
    public DOFiles() { }
    #endregion

    #region Class Properties
    #region DO Properties
		/// <summary>
		/// FileNo
		/// </summary>
		/// <remarks>
		/// This property contains the Files FileNo
		/// </remarks>
		public string FileNo
		{
			get { return (this.m_FileNo); }
			set { this.m_FileNo = value; }
		}

		/// <summary>
		/// BoxNo
		/// </summary>
		/// <remarks>
		/// This property contains the Files BoxNo
		/// </remarks>
		public string BoxNo
		{
			get { return (this.m_BoxNo); }
			set { this.m_BoxNo = value; }
		}

		/// <summary>
		/// DivisionName
		/// </summary>
		/// <remarks>
		/// This property contains the Files DivisionName
		/// </remarks>
		public string DivisionName
		{
			get { return (this.m_DivisionName); }
			set { this.m_DivisionName = value; }
		}

		/// <summary>
		/// DepartmentName
		/// </summary>
		/// <remarks>
		/// This property contains the Files DepartmentName
		/// </remarks>
		public string DepartmentName
		{
			get { return (this.m_DepartmentName); }
			set { this.m_DepartmentName = value; }
		}

		/// <summary>
		/// CategoryName
		/// </summary>
		/// <remarks>
		/// This property contains the Files CategoryName
		/// </remarks>
		public string CategoryName
		{
			get { return (this.m_CategoryName); }
			set { this.m_CategoryName = value; }
		}

		/// <summary>
		/// ProductName
		/// </summary>
		/// <remarks>
		/// This property contains the Files ProductName
		/// </remarks>
		public string ProductName
		{
			get { return (this.m_ProductName); }
			set { this.m_ProductName = value; }
		}

		/// <summary>
		/// ArchiveId
		/// </summary>
		/// <remarks>
		/// This property contains the Files ArchiveId
		/// </remarks>
		public int ArchiveId
		{
			get { return (this.m_ArchiveId); }
			set { this.m_ArchiveId = value; }
		}

		/// <summary>
		/// FileStatus
		/// </summary>
		/// <remarks>
		/// This property contains the Files FileStatus
		/// </remarks>
		public string FileStatus
		{
			get { return (this.m_FileStatus); }
			set { this.m_FileStatus = value; }
		}

		/// <summary>
		/// Notes
		/// </summary>
		/// <remarks>
		/// This property contains the Files Notes
		/// </remarks>
		public string Notes
		{
			get { return (this.m_Notes); }
			set { this.m_Notes = value; }
		}

		/// <summary>
		/// Description
		/// </summary>
		/// <remarks>
		/// This property contains the Files Description
		/// </remarks>
		public string Description
		{
			get { return (this.m_Description); }
			set { this.m_Description = value; }
		}

		/// <summary>
		/// FromNo
		/// </summary>
		/// <remarks>
		/// This property contains the Files FromNo
		/// </remarks>
		public int FromNo
		{
			get { return (this.m_FromNo); }
			set { this.m_FromNo = value; }
		}

		/// <summary>
		/// ToNo
		/// </summary>
		/// <remarks>
		/// This property contains the Files ToNo
		/// </remarks>
		public int ToNo
		{
			get { return (this.m_ToNo); }
			set { this.m_ToNo = value; }
		}

		/// <summary>
		/// FromDate
		/// </summary>
		/// <remarks>
		/// This property contains the Files FromDate
		/// </remarks>
		public DateTime FromDate
		{
			get { return (this.m_FromDate); }
			set { this.m_FromDate = value; }
		}

		/// <summary>
		/// ToDate
		/// </summary>
		/// <remarks>
		/// This property contains the Files ToDate
		/// </remarks>
		public DateTime ToDate
		{
			get { return (this.m_ToDate); }
			set { this.m_ToDate = value; }
		}

		/// <summary>
		/// FromAlpha
		/// </summary>
		/// <remarks>
		/// This property contains the Files FromAlpha
		/// </remarks>
		public string FromAlpha
		{
			get { return (this.m_FromAlpha); }
			set { this.m_FromAlpha = value; }
		}

		/// <summary>
		/// ToAlpha
		/// </summary>
		/// <remarks>
		/// This property contains the Files ToAlpha
		/// </remarks>
		public string ToAlpha
		{
			get { return (this.m_ToAlpha); }
			set { this.m_ToAlpha = value; }
		}

		/// <summary>
		/// CreatedDate
		/// </summary>
		/// <remarks>
		/// This property contains the Files CreatedDate
		/// </remarks>
		public DateTime CreatedDate
		{
			get { return (this.m_CreatedDate); }
			set { this.m_CreatedDate = value; }
		}

		/// <summary>
		/// CreatedByUserId
		/// </summary>
		/// <remarks>
		/// This property contains the Files CreatedByUserId
		/// </remarks>
		public long CreatedByUserId
		{
			get { return (this.m_CreatedByUserId); }
			set { this.m_CreatedByUserId = value; }
		}

		/// <summary>
		/// RequestId
		/// </summary>
		/// <remarks>
		/// This property contains the Files RequestId
		/// </remarks>
		public int RequestId
		{
			get { return (this.m_RequestId); }
			set { this.m_RequestId = value; }
		}

		/// <summary>
		/// RequestDate
		/// </summary>
		/// <remarks>
		/// This property contains the Files RequestDate
		/// </remarks>
		public DateTime RequestDate
		{
			get { return (this.m_RequestDate); }
			set { this.m_RequestDate = value; }
		}

		/// <summary>
		/// RequestedByUserId
		/// </summary>
		/// <remarks>
		/// This property contains the Files RequestedByUserId
		/// </remarks>
		public long RequestedByUserId
		{
			get { return (this.m_RequestedByUserId); }
			set { this.m_RequestedByUserId = value; }
		}

		/// <summary>
		/// RequestedDate
		/// </summary>
		/// <remarks>
		/// This property contains the Files RequestedDate
		/// </remarks>
		public DateTime RequestedDate
		{
			get { return (this.m_RequestedDate); }
			set { this.m_RequestedDate = value; }
		}
		#endregion
    
	#region Default Properties
	public List<DOFiles> Filess
	{
	  get { return m_Filess; }
	  set { m_Filess = value; }
	}    
	#endregion
	
    #endregion

    #region Class Methods
    public bool Retrieve()
    {
      sqlData = new SQLDataObject();
      DataSet resultDS = sqlData.ExecuteDataSetSQL(m_StoredProcedureConstRetrieve + " @" + RowFileNo + "=" + this.FileNo);
      return SetClassPropertiesFromDataSet(resultDS);
    }

    public bool RetrieveAll()
    {
      sqlData = new SQLDataObject();
      string sVariables = sqlData.GetVariables(this);

      DataSet resultDS = sqlData.ExecuteDataSetSQL(m_StoredProcedureConstRetrieveall + " " + sVariables);
      return SetClassPropertiesListFromDataSet(resultDS);
    }

    public bool Create()
    {
      bool success = false;
      sqlData = new SQLDataObject();
      string sVariables = sqlData.GetVariables(this);

      success = sqlData.ExecuteNonQuerySQL(m_StoredProcedureConstCreate + " " + sVariables);

      return success;
    }

    public bool Update()
    {
      bool success = false;
      sqlData = new SQLDataObject();

      string sVariables = sqlData.GetVariables(this);

      success = sqlData.ExecuteNonQuerySQL(m_StoredProcedureConstUpdate + " " + sVariables);

      return success;
    }

    private bool SetClassPropertiesFromDataSet(DataSet resultDS)
    {
      bool success = false;
      if (resultDS.Tables[0] != null)
      {
        if (resultDS.Tables[0].Rows.Count > 0)
        {
          foreach (DataRow dr in resultDS.Tables[0].Rows)
          {
					if (dr[RowFileNo].ToString() != "")
			this.FileNo = dr[RowFileNo].ToString();

		if (dr[RowBoxNo].ToString() != "")
			this.BoxNo = dr[RowBoxNo].ToString();

		if (dr[RowDivisionName].ToString() != "")
			this.DivisionName = dr[RowDivisionName].ToString();

		if (dr[RowDepartmentName].ToString() != "")
			this.DepartmentName = dr[RowDepartmentName].ToString();

		if (dr[RowCategoryName].ToString() != "")
			this.CategoryName = dr[RowCategoryName].ToString();

		if (dr[RowProductName].ToString() != "")
			this.ProductName = dr[RowProductName].ToString();

		if (dr[RowArchiveId].ToString() != "")
			this.ArchiveId = int.Parse(dr[RowArchiveId].ToString());

		if (dr[RowFileStatus].ToString() != "")
			this.FileStatus = dr[RowFileStatus].ToString();

		if (dr[RowNotes].ToString() != "")
			this.Notes = dr[RowNotes].ToString();

		if (dr[RowDescription].ToString() != "")
			this.Description = dr[RowDescription].ToString();

		if (dr[RowFromNo].ToString() != "")
			this.FromNo = int.Parse(dr[RowFromNo].ToString());

		if (dr[RowToNo].ToString() != "")
			this.ToNo = int.Parse(dr[RowToNo].ToString());

		if (dr[RowFromDate].ToString() != "")
			this.FromDate = DateTime.Parse(dr[RowFromDate].ToString());

		if (dr[RowToDate].ToString() != "")
			this.ToDate = DateTime.Parse(dr[RowToDate].ToString());

		if (dr[RowFromAlpha].ToString() != "")
			this.FromAlpha = dr[RowFromAlpha].ToString();

		if (dr[RowToAlpha].ToString() != "")
			this.ToAlpha = dr[RowToAlpha].ToString();

		if (dr[RowCreatedDate].ToString() != "")
			this.CreatedDate = DateTime.Parse(dr[RowCreatedDate].ToString());

		if (dr[RowCreatedByUserId].ToString() != "")
			this.CreatedByUserId = long.Parse(dr[RowCreatedByUserId].ToString());

		if (dr[RowRequestId].ToString() != "")
			this.RequestId = int.Parse(dr[RowRequestId].ToString());

		if (dr[RowRequestDate].ToString() != "")
			this.RequestDate = DateTime.Parse(dr[RowRequestDate].ToString());

		if (dr[RowRequestedByUserId].ToString() != "")
			this.RequestedByUserId = long.Parse(dr[RowRequestedByUserId].ToString());

		if (dr[RowRequestedDate].ToString() != "")
			this.RequestedDate = DateTime.Parse(dr[RowRequestedDate].ToString());
          }
          success = true;
        }
      }
      return success;
    }

    private bool SetClassPropertiesListFromDataSet(DataSet resultDS)
    {
      bool success = false;
      if (resultDS.Tables[0] != null)
      {
        if (resultDS.Tables[0].Rows.Count > 0)
        {
          foreach (DataRow dr in resultDS.Tables[0].Rows)
          {
            DOFiles Files = new DOFiles();
			
					if (dr[RowFileNo].ToString() != "")
			Files.FileNo = dr[RowFileNo].ToString();

		if (dr[RowBoxNo].ToString() != "")
			Files.BoxNo = dr[RowBoxNo].ToString();

		if (dr[RowDivisionName].ToString() != "")
			Files.DivisionName = dr[RowDivisionName].ToString();

		if (dr[RowDepartmentName].ToString() != "")
			Files.DepartmentName = dr[RowDepartmentName].ToString();

		if (dr[RowCategoryName].ToString() != "")
			Files.CategoryName = dr[RowCategoryName].ToString();

		if (dr[RowProductName].ToString() != "")
			Files.ProductName = dr[RowProductName].ToString();

		if (dr[RowArchiveId].ToString() != "")
			Files.ArchiveId = int.Parse(dr[RowArchiveId].ToString());

		if (dr[RowFileStatus].ToString() != "")
			Files.FileStatus = dr[RowFileStatus].ToString();

		if (dr[RowNotes].ToString() != "")
			Files.Notes = dr[RowNotes].ToString();

		if (dr[RowDescription].ToString() != "")
			Files.Description = dr[RowDescription].ToString();

		if (dr[RowFromNo].ToString() != "")
			Files.FromNo = int.Parse(dr[RowFromNo].ToString());

		if (dr[RowToNo].ToString() != "")
			Files.ToNo = int.Parse(dr[RowToNo].ToString());

		if (dr[RowFromDate].ToString() != "")
			Files.FromDate = DateTime.Parse(dr[RowFromDate].ToString());

		if (dr[RowToDate].ToString() != "")
			Files.ToDate = DateTime.Parse(dr[RowToDate].ToString());

		if (dr[RowFromAlpha].ToString() != "")
			Files.FromAlpha = dr[RowFromAlpha].ToString();

		if (dr[RowToAlpha].ToString() != "")
			Files.ToAlpha = dr[RowToAlpha].ToString();

		if (dr[RowCreatedDate].ToString() != "")
			Files.CreatedDate = DateTime.Parse(dr[RowCreatedDate].ToString());

		if (dr[RowCreatedByUserId].ToString() != "")
			Files.CreatedByUserId = long.Parse(dr[RowCreatedByUserId].ToString());

		if (dr[RowRequestId].ToString() != "")
			Files.RequestId = int.Parse(dr[RowRequestId].ToString());

		if (dr[RowRequestDate].ToString() != "")
			Files.RequestDate = DateTime.Parse(dr[RowRequestDate].ToString());

		if (dr[RowRequestedByUserId].ToString() != "")
			Files.RequestedByUserId = long.Parse(dr[RowRequestedByUserId].ToString());

		if (dr[RowRequestedDate].ToString() != "")
			Files.RequestedDate = DateTime.Parse(dr[RowRequestedDate].ToString());

            this.Filess.Add(Files);
          }
          success = true;
        }
      }
      return success;
    }
    #endregion

    #region Class Support Methods
    #endregion
  }
}
